package com.fw.ui.view.settings.usercontrol.bouser.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.ui.view.event.AbstractValueChangeListener;
import com.fw.ui.view.settings.usercontrol.bouser.CreateBOUserView;
import com.vaadin.data.Property.ValueChangeEvent;

@Component
@Scope(SCOPE_PROTOTYPE)
public class CreateBOUserEmailValueChangeListener extends AbstractValueChangeListener {

    private static final long serialVersionUID = 1L;

    @Override
    public boolean validate(ValueChangeEvent event) throws Exception {
	CreateBOUserView createBOUserView = (CreateBOUserView) this.getBasedComponent();
	createBOUserView.getRow2Validate().setVisible(false);
	createBOUserView.getLblEmailValidateMessage().setValue("");
	createBOUserView.getTxtEmail().removeStyleName("v-textfield-error");
	boolean emailValid = createBOUserView.getTxtEmail().isValid();
	if (!emailValid) {
	    createBOUserView.getTxtEmail().addStyleName("v-textfield-error");
	    if (createBOUserView.getTxtEmail().getErrorMessage() != null) {
		createBOUserView.getLblEmailValidateMessage().setValue(
			createBOUserView.getTxtEmail().getErrorMessage().getFormattedHtmlMessage());
	    }
	    createBOUserView.getRow2Validate().setVisible(true);
	}
	return true;
    }

    @Override
    public void change(ValueChangeEvent event) throws Exception {
	// TODO Auto-generated method stub

    }

}
